/**
 * Created by emmett on 18-3-6.
 */

//自定义扩展
jQuery.validator.addMethod("isMobile", function (value, element) {
    var length = value.length;
    var mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
    return this.optional(element) || (length == 11 && mobile.test(value));
}, "手机格式不正确");
jQuery.validator.addMethod("isEmail", function (value, element) {
    var email = /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
    return this.optional(element) || email.test(true);
}, "邮箱格式不正确");
jQuery.validator.addMethod("filterDBcom", function (value, element) {
    var command = /select|update|delete|insert|declare|dbcc|alter|drop|creat|backup|add|set|open|close|exec|count|’|"|=|;|>|<|%/i;
    return this.optional(element) || !(command.test(value));
}, "不能包含sql特殊字符");
jQuery.validator.addMethod("filterHTML", function (value, element) {
    var chrnum = /<[^>]+>/;
    return this.optional(element) || !(chrnum.test(value));
}, "不用包含html字符");
jQuery.validator.addMethod("isIp", function (value, element) {
    var chrnum = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
    return this.optional(element) || chrnum.test(value);
}, "ip格式不正确");
jQuery.validator.addMethod("haveBlank", function (value, element) {
    var is = value.indexOf(" ") >= 0 ? false : true;
    return this.optional(element) || is;
}, "不能包含空格");

// 联系电话(手机/电话皆可)验证
jQuery.validator.addMethod("isPhone", function (value, element) {
    var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;
    var tel = /^\d{3,4}-?\d{7,9}$/;
    return this.optional(element) || (tel.test(value) || mobile.test(value));

}, "请正确填写您的联系电话");

jQuery.validator.addMethod("atLeastOne", function (value, element, eles) {
    for (var i in eles) {
        if ($(eles[i]).val() != '') {
            return true;
        }
    }
    return false;
}, "请至少填写一项");

//错误提示信息创建什么标签<label>xxxx</label>
// $.validator.setDefaults({
//     errorElement : "label"
// });